package com.yuebao.service.impl;

import com.yuebao.api.FundStockService;
import com.yuebao.request.TransactionDTO;
import com.yuebao.service.IFundCommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class FundCommonService implements IFundCommonService {
    
    @Resource
    FundStockService fundStockService;
    
    
    @Override
    public Boolean reduceFundShare(TransactionDTO transactionDTO) {
    
        boolean isSuccess = fundStockService.update()
                .setSql("stock=stock-" + transactionDTO.getShare())
                .eq("fund_id", transactionDTO.getFundId())
                .gt("stock",transactionDTO.getShare())
                .update();
        if (!isSuccess)
            log.error("数据库扣减份额失败");
    
        log.info("数据库扣减份额成功");
        return isSuccess;
    }
}
